package fr.cephb.joperon.webapp;


import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.annotation.Resource;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;

import fr.cephb.lang.Endian;



/**
 * OperonWebAppListener
 * @author lindenb
 *
 */
public class OperonWebAppListener implements ServletContextListener
	{
	@SuppressWarnings("unused")
	@Resource(name="jdbc/OperonDS")
	private DataSource datasource;
	
	
	@Override
	public void contextInitialized(ServletContextEvent context)
		{
		InputStream in= this.getClass().getResourceAsStream("LocalSettings.properties");
		if(in!=null)
			{
			Properties prop= new Properties();
			try {
				prop.loadFromXML(in);
				in.close();
				String s = prop.getProperty("ENDIAN");
				if(s!=null)
					{
					if(s.equalsIgnoreCase("SMALL"))
						{
						Endian.setDefault(Endian.SMALL);
						}
					else  if(s.equalsIgnoreCase("BIG"))
						{
						Endian.setDefault(Endian.BIG);
						}
					else
						{
						context.getServletContext().log("Unknown indianess "+s);
						}
					}
				} 
			catch (IOException e)
				{
				context.getServletContext().log("Cannot read Local Settings",e);
				}
			}

		}
	
	@Override
	public void contextDestroyed(ServletContextEvent context)
		{
		
		}
	
	
	
	}